package com.forestar.mapControl.utils.mapConvert.task;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;

import com.forestar.mapControl.utils.BitmapUtils;
import com.forestar.mapControl.utils.FileSizeUtil;
import com.forestar.mapControl.utils.LogD;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * created by  xzk
 * 2020/8/4   14:20
 * 说明:  按照文件夹，读取多种图层的task
 */
public class LoadFileOverlayTileTask extends LoadTileCommonTask {

    public LoadFileOverlayTileTask(AtomicInteger hasTaskNum) {
        super(hasTaskNum);
    }

    @Override
    public void getBitmapListFromFile() {

        String tempFileDirectory = buildTempFileDirectory();
        File t1 = new File(tempFileDirectory);
        File[] files = t1.listFiles();
        if (null == files || files.length < 1) {
            return;
        }
        //保存了多个图层的文件夹
        for (File file : files) {
            if (!file.isDirectory()) {
            } else {
                if (!file.getPath().contains("no")) {
                    File[] tileList = file.listFiles();
                    //拿到地图文件
                    if (null != tileList && tileList.length > 0) {
                        List<Bitmap> layerBitmap = new ArrayList<>();
                        for (File tile : tileList) {
                            if (!tile.isDirectory()) {
                                Bitmap bitmap = BitmapFactory.decodeFile(tile.getAbsolutePath());
                                bitmap = BitmapUtils.drawBg4Bitmap(Color.WHITE, bitmap);
                                layerBitmap.add(bitmap);
                            }
                        }
                        multiLevelTempList.add(layerBitmap);
                    }
                }
            }
        }
        //不符合最大数量，再次添加  最大为1万张
        while (bitmapTempList.size() < fileMaxSize) {
            bitmapTempList.addAll(bitmapTempList);
        }
    }
}
